file = open("18.data", "r")
tree = []
for line in file :
	tree.append([])
	for num in line.split(" ") :
		try :
			tree[-1].append(int(num))
		except ValueError:
			pass

def children(row, col) :
	if row == 14 : return ()
	return ((row+1, col), (row+1, col+1))

def search(tree, row, col) :
	c = children(row, col)
	if c :
		return max(search(tree, *c[0]), search(tree, *c[1])) + tree[row][col]
	else :
		return tree[row][col]

print tree

print search(tree, 0, 0)